package Store;

import Auxiliary.Sequence_Row;
import Auxiliary.Sequence_StateObserver;
import Auxiliary.Sequence_Value;
import DataView.Sequence_Error;
import Visualization.StateTableVis;

public class StateTable extends Element 
{
	public Sequence_StateObserver used = new Sequence_StateObserver();
	public Sequence_Row row = new Sequence_Row();

	public Sequence_Error check() 
	{
		Sequence_Error lista = new Sequence_Error();
		for (Row r : row.getAll())
		{
			int i=0;
			for(Row s : row.getAll()){
				if(r.getName().compareTo("impossible")!=0)
						if(r.getName().equals(s.getName()))
							i++;
			}
			if(i>1)
			{
				lista.add("There are Two or more States with the same name "+ r.getName());
				break;
			}				
		}
		return lista;
	}

	public void setUsedSO(Sequence_StateObserver aSoUsed) 
	{
		used = aSoUsed; 
	}

	public void setROW(Sequence_Row aNewRows) 
	{
		row = aNewRows;
	}

	public Sequence_StateObserver getUsedSO()
	{
		return used;
	}
	
	public Row getRow(int i)
	{
		return row.get(i);
	}
	
	public void defineState(Row aRow, String aName) 
	{
		row.find(aRow).setName(aName);
	}
	
	public StateTableVis vis()
	{
		return new StateTableVis(used.vis_seq_so(), row);
	}

	public Row findRow(Sequence_Value values) 
	{
		for(Row r : row.getAll())
			if(r.getValues().uguale(values))
				return r;
		return null;
	}
}